package flc.ast.dialog;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;

import androidx.annotation.NonNull;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.adapter.WheelAdapter;
import com.contrarywind.view.WheelView;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;

import flc.ast.databinding.DialogNoteBinding;
import stark.common.basic.base.BaseSmartDialog;

public class NoteDialog extends BaseSmartDialog<DialogNoteBinding> implements View.OnClickListener {

    private int currentNotes;
    private List<Integer> noteList;
    private List<String> noteStrList;

    public NoteDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    public void setNote(int notes) {
        currentNotes = notes;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_note;
    }

    @Override
    protected void initView(View view) {
        mDataBinding.ivNoteCancel.setOnClickListener(this);
        mDataBinding.ivNoteConfirm.setOnClickListener(this);

        noteList = new ArrayList<>();
        noteList.add(1);
        noteList.add(2);
        noteList.add(4);
        noteList.add(8);
        noteList.add(16);

        noteStrList=new ArrayList<>();
        noteStrList.add("1");
        noteStrList.add("2");
        noteStrList.add("4");
        noteStrList.add("8");
        noteStrList.add("16");

        int startPos = 0;
        for (int i = 0; i < noteList.size(); i++) {
            if (noteList.get(i) == currentNotes) {
                startPos = i;
                break;
            }
        }

        WheelAdapter adapter = new ArrayWheelAdapter(noteStrList);
        mDataBinding.wvNote.setAdapter(adapter);

        mDataBinding.wvNote.setTextColorCenter(Color.parseColor("#71FFCB"));
        mDataBinding.wvNote.setTextSize(28);
        mDataBinding.wvNote.setDividerColor(Color.parseColor("#80282A30"));
        mDataBinding.wvNote.setDividerType(WheelView.DividerType.FILL);
        mDataBinding.wvNote.setItemsVisibleCount(3);
        mDataBinding.wvNote.setCurrentItem(startPos);
        mDataBinding.wvNote.setCyclic(false);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ivNoteCancel:
                dismiss();
                break;
            case R.id.ivNoteConfirm:
                dismiss();
                if (listener != null) {
                    listener.onClickConfirm(noteList.get(mDataBinding.wvNote.getCurrentItem()));
                }
                break;
        }
    }

    private IListener listener;

    public void setListener(IListener listener) {
        this.listener = listener;
    }

    public interface IListener {
        void onClickConfirm(int note);
    }
}
